package util;

import java.util.LinkedList;

public class ByteList extends LinkedList<Byte> {

	private static final long	serialVersionUID	= 1L;

	public ByteList( ) {
		super( );
	}

	/**
	 * @param b
	 * @return
	 */
	public ByteList concat( byte b ) {
		super.add( b );
		return this;
	}

	/**
	 * @param bts
	 * @return
	 */
	public ByteList concat( byte[] bts ) {
		for ( int i = 0 ; i < bts.length ; i++ )
			super.add( bts[i] );

		return this;
	}

	public byte[] toByteArray( ) {
		byte[] data = new byte[this.size( )];
		for ( int i = 0 ; i < data.length ; i++ )
			data[i] = this.get( i );
		return data;
	}

	@Override
	public String toString( ) {
		StringBuilder stb = new StringBuilder( );
		String tmp;
		for ( byte b : this ) {
			tmp = Integer.toBinaryString( b );
			if ( tmp.length( ) > 8 ) tmp = tmp.substring( 24 );
			stb.append( "| " + tmp + " |" );
		}
		return stb.toString( );
	}
}
